﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using ShevaEngine.Core.Interfaces;

namespace ShevaEngine2.Modules.Animations
{
    /// <summary>
    /// Animations manager.
    /// </summary>
    public class AnimationsManager : IUpdateAble
    {
        /// <summary>Singleton.</summary>
        public static readonly AnimationsManager Instance = new AnimationsManager();

        /// <summary>Animation players.</summary>
        private List<AnimationPlayer> AnimationPlayers;
        /// <summary>Indexer.</summary>
        private Int32 Indexer;

        /// <summary>
        /// Constructor.
        /// </summary>
        public AnimationsManager()
        {
            this.AnimationPlayers = new List<AnimationPlayer>();
        }

        /// <summary>
        /// Method Update().
        /// </summary>
        /// <param name="time"></param>
        public void Update(Microsoft.Xna.Framework.GameTime time)
        {
            for (this.Indexer = this.AnimationPlayers.Count - 1; this.Indexer >= 0; this.Indexer--)                
                this.AnimationPlayers[this.Indexer].Update(time);
        }

        /// <summary>
        /// Method creates new Animation Player.
        /// </summary>
        /// <param name="skinnigData"></param>
        /// <returns></returns>
        internal AnimationPlayer CreateAnimationPlayer(SkinningData skinningData)
        {
            AnimationPlayer newAnimationPlayer = new AnimationPlayer(skinningData);

            this.AnimationPlayers.Add(newAnimationPlayer);

            return newAnimationPlayer;
        }
    }
}
